<template>
  <div style="width: 1200px;margin:0 auto;">
    <el-row :gutter="20">
      <el-col :span="12">
        <el-card >
          <img src="/imgs/reg.png" width="100%">
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-form label-width="80px" style="margin-top: 50px;" >
          <el-form-item >
              <h1 style="font-size:30px;">
                  立即注册
                  <a href="/login" style="color: #078df5;float: right;text-decoration: none;font-size: 15px;">已有账号?现在登录</a>
              </h1>
          </el-form-item>
          <el-form-item label="用户名">
            <el-input placeholder="请输入用户名" v-model="user.username" ></el-input>
          </el-form-item>
          <el-form-item label="密码">
            <el-input type="password" placeholder="请输入密码"  v-model="user.password"></el-input>
          </el-form-item>
          <el-form-item label="昵称">
            <el-input placeholder="请输入昵称"  v-model="user.nickname"></el-input>
          </el-form-item>
          <el-form-item style="text-align: center;">
            <el-button type="primary" style="position: relative;right: 20px;" @click="reg()">注册</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  data() {
    return {
      user: {
        username:'',
        password:'',
        nickname: ''
      }
    }
  },
  methods: {
    reg() {
      let url = this.BASE_URL + '/v1/users/reg'
      //将json对象转化为字符串对象
      let data = this.qs.stringify(this.user)
      console.log(data)
      this.axios.post(url,data).then(reponse=>{
        if(reponse.data.code==1){
          this.$message.success("注册成功！")
          this.$router.push('/login')
        }else{
          this.$message.error(reponse.data.msg)
        }
      })
    }
  },

}
</script>

<style scoped>

</style>
